﻿function btn_Back() {
	window.location = "CurrentTeamRecap.html";
}



var myCoord;
var dataEtapes;
var markers=[];
var map;
var equipeId = window.localStorage.getItem("selectedTeamId");


function initializeMap(){
	var mapOptions = {
		center: new google.maps.LatLng(0, 0),
		zoom: 14,
		mapTypeId: google.maps.MapTypeId.HYBRID
	};
	map = new google.maps.Map(document.getElementById("map_canvas"),
		mapOptions);
		
	interactionWebService.etapesEquipe(onResponseEtapesEquipe,
										 onErreurEtapesEquipe,
										 equipeId);
}

function onResponseEtapesEquipe(data) {
	dataEtapes = data;
	interactionWebService.infoEquipe(onResponseInfoEquipe,
										 onErreurInfoEquipe,
										 equipeId);
}

function onErreurEtapesEquipe(erreur) {
	alert("Impossible de récupérer les positions des étapes : " + erreur);
}

function onResponseInfoEquipe(data) {
	myCoord = new google.maps.LatLng(data[0].coordx, data[0].coordy);
	showEtapes();
}

function onErreurInfoEquipe(erreur) {
	alert("Impossible de récupérer la position de l'équipe : " + erreur);
}

function showEtapes(){
	var mapBounds = new google.maps.LatLngBounds();
	
	
	mapBounds.extend(myCoord);
	var image = {
		url: '././css/images/iconTeam.png',
		size: new google.maps.Size(48, 48),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(24, 48),
		scaledSize: new google.maps.Size(32, 32)
	};
	var m1 = new google.maps.Marker({
	position: myCoord,
	title: 'Localisation Equipe',
	map: map,
	icon : image
	});
	
	
	$.each(dataEtapes, function(i, v) {			
		var coord = new google.maps.LatLng(v.coordx, v.coordy);
		mapBounds.extend(coord);
		if(v.etat == 1){
			var url = '././css/images/etapeTodo.png';
		}else if(v.etat == 2){
			var url = '././css/images/etapeDone.png';
		};
		var image = {
			url: url,
			size: new google.maps.Size(48, 48),
			origin: new google.maps.Point(0, 0),
			anchor: new google.maps.Point(0, 48),
			scaledSize: new google.maps.Size(32, 32)
		};
		markers[i] = new google.maps.Marker({
		position: coord,
		title: v.numero,
		map: map,
		icon : image
		});	
	});	
	 
	map.fitBounds(mapBounds);
}

/*function showEtapes(map){
	var mapBounds = new google.maps.LatLngBounds();	
	
	// position actuelle
	var coord = new google.maps.LatLng('42.843','-0.484'); 	
	mapBounds.extend(coord);
	var image = {
		url: '././css/images/iconTeam.png',
		size: new google.maps.Size(48, 48),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(24, 48),
		scaledSize: new google.maps.Size(32, 32)
	};
	var markerOne = new google.maps.Marker({
	position: coord,
	title: 'position actuelle',
	map: map,
	icon : image
	});
	 
	// get etapes position here
	 
	var teamcoord2 = new google.maps.LatLng('44.543', '-0.514');	
	mapBounds.extend(teamcoord2);
	var image = {
		url: '././css/images/iconEtapeNext.png',
		size: new google.maps.Size(48, 48),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(24, 48),
		scaledSize: new google.maps.Size(32, 32)
	};
	var markerTwo = new google.maps.Marker({
	position: teamcoord2,
	title: 'Une mairie difficile',
	map: map,
	icon : image
	});	
	 
	 
	var teamcoord3 = new google.maps.LatLng('43.543', '-0.514');	
	mapBounds.extend(teamcoord3);
	var image = {
		url: '././css/images/iconEtapeWin.png',
		size: new google.maps.Size(48, 48),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(24, 48),
		scaledSize: new google.maps.Size(32, 32)
	};
	var markerThree = new google.maps.Marker({
	position: teamcoord3,
	title: 'bachibouzouk',
	map: map,
	icon : image
	});	
	
	 
	map.fitBounds(mapBounds);
}*/